package com.dongdongshop.quartz;

import com.dongdongshop.mapper.TbUserMapper;
import com.dongdongshop.pojo.TbUser;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @Description
 * @ClassName UserJob
 * @Author RC
 * @date 2021.01.06 16:38
 */
@Component
public class UserJob {
    @Resource
    private TbUserMapper tbUserMapper;
    @Scheduled(cron = "0/30 * * * * ?")
    public void findUserNoLogin() {
        long time = new Date().getTime();
        long time1 = 30*1000;
        List<TbUser> tbUsers = tbUserMapper.selectByExample(null);
        for (TbUser tbUser : tbUsers) {
            if(time - tbUser.getLastLoginTime().getTime() > time1 ){
                System.out.println("30秒未登录的用户有" + tbUser.getUsername());
            }
        }
    }
}
